package org.ukpass.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.BreakIterator;

import android.os.Environment;
import android.util.Log;

public class FilePathUtil {
	private static final String CLASS_NAME = "---FilePathUtil---";

	// get SDCard Path
	public static String getSDCardPath() {
		Boolean isExist = Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED);
		if (isExist) {
			String SDCardPath = Environment.getExternalStorageDirectory()
					.toString();
			return SDCardPath;
		} else {
			
			Log.i(CLASS_NAME, "SDCard is not exist!");
			//
			
			return null;
		}
	}

	public static void CreateDirectoryXMLFile(String content) {
		String filePath = getSDCardPath() + "/ESP_NISK/nisk.xml";
		File parentPath = new File(filePath).getParentFile();
		if (!parentPath.exists()) {
			parentPath.mkdirs();
		}
		FileOutputStream fileOutputStream;
		try {
			fileOutputStream = new FileOutputStream(filePath);
			fileOutputStream.write(content.getBytes());
			fileOutputStream.flush();
			fileOutputStream.close();
		} catch (Exception e) {
			Log.e(CLASS_NAME, "---CreateDirectoryXMLFile failed!---");
		}

	}

	public static void CreateFastDFSConf(String content) {
		String filePath = getSDCardPath() + "/ESP_NISK/fdfs_client.conf";
		File parentPath = new File(filePath).getParentFile();
		if (!parentPath.exists()) {
			parentPath.mkdirs();
		}
		FileOutputStream fileOutputStream;
		try {
			fileOutputStream = new FileOutputStream(filePath);
			fileOutputStream.write(content.getBytes());
			fileOutputStream.flush();
			fileOutputStream.close();
		} catch (Exception e) {
			Log.e(CLASS_NAME, e.getLocalizedMessage());
		}
	}

}
